﻿package mortal.game.view.common.tooltip.tooltips
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.primitives.object2d.*;
    import frEngine.render.layer.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.tooltip.tooltips.base.*;
    import mortal.game.view.firstReCharge.*;
    import mortal.game.view.vip.panel.*;

    public class TooltipFirstRecharge extends ToolTipScaleBg implements IWindow3D, IToolTip3D
    {
        protected var _3dBg:GImageBitmap;
        private var _3dName:GTextFiled;
        private var _3dDescItem:EffectItem;
        private var _tipsTxt:GImageBitmap;
        private var _combatBg:GImageBitmap;
        private var _addComabte:BitmapNumberText;
        private var _bg:ScaleBitmap;
        private var _titleBg:GImageBitmap;
        private var _contentBmd:BitmapData;
        private var _modelContent:Model3dBasePanel;
        protected var _rect3d:Rect3DObject;
        protected var _img2d:Img2D;
        protected var _img2dTitle:Img2D;
        protected var _tModule:TModelShow;
        protected var _contentTopOf3DSprite:Sprite;
        private var _isDisposed:Boolean;

        public function TooltipFirstRecharge()
        {
            this._contentTopOf3DSprite = new Sprite();
            return;
        }// end function

        override public function get width() : Number
        {
            return 360;
        }// end function

        override public function get height() : Number
        {
            return 410;
        }// end function

        public function get contentTopOf3DSprite() : Sprite
        {
            return this._contentTopOf3DSprite;
        }// end function

        public function get contentContainer() : Sprite
        {
            return this;
        }// end function

        protected function createChildren() : void
        {
            this.updateSize(360, 410);
            this._isDisposed = false;
            this._3dBg = UIFactory.gImageBitmap(ImagesConst.VipTipsBg, 0, 0, null, this.update3DModule);
            this._bg = UIFactory.bg(0, 0, 360, 410, this, ImagesConst.ToolTipBgBai);
            this._titleBg = UIFactory.gImageBitmap("", 282 - 296, -10, this._contentTopOf3DSprite, this.drawTitle);
            this._3dDescItem = UICompomentPool.getUICompoment(EffectItem);
            this._3dDescItem.setItemStyle(ItemStyleConst.Small, null);
            this._3dDescItem.move(314 - 295, 232 - 208);
            this._contentTopOf3DSprite.addChild(this._3dDescItem);
            var _loc_1:* = GlobalStyle.textFormatChen.center();
            _loc_1.size = 18;
            this._3dName = UIFactory.gTextField("", 415 - 68 - 265, 238 - 208, 150, 35, this._contentTopOf3DSprite, _loc_1);
            this._modelContent = UICompomentPool.getUICompoment(Model3dBasePanel);
            this._combatBg = UIFactory.gImageBitmap("", 500 - 265, 220 - 208, this._contentTopOf3DSprite, this.drawTitle);
            this._addComabte = UIFactory.bitmapNumberText(128 + 428 - 265, 10 + 215 - 208, "GuildCopyNum.png", 24, 32, -6, this._contentTopOf3DSprite, 9, BitmapNumberText.Mid);
            this.addEventListener(Event.REMOVED_FROM_STAGE, this.removeFromeStageHandler);
            return;
        }// end function

        protected function removeFromeStageHandler(event:Event) : void
        {
            this._isDisposed = true;
            this._titleBg.dispose();
            this._titleBg = null;
            this._combatBg.dispose();
            this._combatBg = null;
            this._3dBg.dispose();
            this._3dBg = null;
            this._3dName.dispose();
            this._3dName = null;
            this._3dDescItem.dispose();
            this._3dDescItem = null;
            this._bg.dispose();
            this._bg = null;
            this._modelContent.dispose();
            this._modelContent = null;
            if (this._contentBmd)
            {
                this._contentBmd.dispose();
                this._contentBmd = null;
            }
            if (this._img2d)
            {
                this._img2d.dispose(true);
                this._img2d = null;
            }
            if (this._img2dTitle)
            {
                this._rect3d.removeImg(this._img2dTitle, true);
                this._img2dTitle = null;
            }
            if (this._rect3d)
            {
                Rect3DManager.instance.closeEndHander(null, this);
                this._rect3d = null;
            }
            this.removeEventListener(Event.REMOVED_FROM_STAGE, this.removeFromeStageHandler);
            this.dispatchEvent(new WindowEvent(WindowEvent.CLOSE_END));
            return;
        }// end function

        private function update3DModule() : void
        {
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_7:Boolean = false;
            var _loc_1:* = new Rectangle(10, paddingTop + 7, 350, 400);
            this._rect3d = Rect3DManager.instance.registerWindow(true, _loc_1, this, true);
            Rect3DManager.instance.windowShowHander(null, this);
            this._modelContent.rect3d = this._rect3d;
            this._modelContent.remove3d();
            if (this._3dBg.bitmapData)
            {
                if (this._img2d)
                {
                    this._img2d.dispose(true);
                }
                this._img2d = new Img2D(null, this._3dBg.bitmapData, new Rectangle(0, 0, 350, 400), false);
                this._img2d.autoDispose = false;
                this._img2d.x = 0;
                this._img2d.y = 0;
                this._rect3d.addImg(this._img2d);
            }
            var _loc_2:* = this._tModule.mesh + ".md5mesh";
            var _loc_3:* = this._tModule.bone + ".skeleton";
            var _loc_4:* = this._tModule.texture;
            var _loc_8:* = int(this._tModule.pos.split("#")[0]) + 55;
            var _loc_9:* = this._tModule.pos.split("#")[1];
            if (this._tModule.isAddAction)
            {
                _loc_7 = true;
            }
            else
            {
                _loc_7 = false;
            }
            if (this._tModule.rotation)
            {
                _loc_5 = this._tModule.rotation.split("#")[0];
                _loc_6 = this._tModule.rotation.split("#")[1];
            }
            this._modelContent.addActionModel(_loc_2, _loc_3, _loc_4, _loc_8, _loc_9, this._tModule.scale * 0.01, _loc_5, _loc_6, this._tModule.actionName, _loc_7);
            this._modelContent.addSelfEffect(this._tModule.selfEffect);
            this._titleBg.imgUrl = ImagesConst.VipPanelRewardTitleBg;
            this._combatBg.imgUrl = ImagesConst.VipAddCombatBg;
            return;
        }// end function

        private function drawTitle() : void
        {
            if (this._isDisposed || this._titleBg.bitmapData == null || this._combatBg.bitmapData == null)
            {
                return;
            }
            this._3dName.text = this._tModule.name;
            if (this._rect3d)
            {
                if (this._img2dTitle)
                {
                    this._img2dTitle.dispose(true);
                }
                this._contentBmd = new BitmapData(this._contentTopOf3DSprite.width, this._contentTopOf3DSprite.height, true, 16777215);
                this._contentBmd.draw(this._contentTopOf3DSprite);
                this._img2dTitle = new Img2D(null, this._contentBmd, new Rectangle(0, 0, this._contentBmd.width, this._contentBmd.height), true);
                this._img2dTitle.autoDispose = false;
                this._img2dTitle.x = 10;
                this._img2dTitle.y = 0;
                this._rect3d.addImg(this._img2dTitle, Layer3DManager.particleLayer);
            }
            return;
        }// end function

        override public function set data(param1) : void
        {
            super.data = param1;
            this._tModule = param1.tModelShow;
            this.createChildren();
            this._3dDescItem.itemData = param1.itemData;
            var _loc_2:* = Cache.instance.firstRecharge.firstRechargeRewardInfo;
            if (_loc_2 && _loc_2.equipIsGet == false)
            {
                this._addComabte.text = "1888";
            }
            else
            {
                this._addComabte.text = "888";
            }
            return;
        }// end function

        public function updatePosition() : void
        {
            this.dispatchEvent(new WindowEvent(WindowEvent.POSITIONCHANGE));
            return;
        }// end function

    }
}
